<?php
namespace app\index\controller;

use think\Controller;

class IndexController extends Controller
{
    public function index()
    {


       //渲染当前的视图
       return  $this->fetch('Chat/login');
    }


    public function register()
    {
        return $this->fetch('Chat/register');
    }


    public function Chat(){
        return $this->fetch('Chat/chat');
    }


    public function addGroup(){
        return $this->fetch('Chat/add_group');
    }


    public function test(){
        return $this->fetch('Chat/chat_test_one');
    }

    public function do_group_add(){
        $client     =   stream_socket_client('tcp://192.168.0.164:9503',$errno,$errstr,20);
        $group_name =   input('post.group_name');
        //因为管理员可以向后台所有用户推送消息
        $send_name  =   json_encode(['type'=>'add_group','group_name'=>$group_name])."\n";
        fwrite($client,$send_name,strlen($send_name));
        $data       =   fread($client,8192);
        var_dump($data);
    }
    
}
